package com.cdream.basic.algorithm.leetcode.linkedlist;

/**
 * @author cdream
 * @date 6/12/21
 */
public class Question206 {
    public ListNode reverseList2(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode cur = dummy.next;
        ListNode next;
        while (cur.next != null) {
            next = cur.next;
            cur.next = next.next;
            next = dummy.next;
            dummy.next = next;

        }

        return dummy.next;
    }

    public ListNode reverseList1(ListNode head) {
        if (head == null) {
            return null;
        }

        ListNode pre = null;
        ListNode cur = head;
        ListNode next = head.next;
        while (cur.next != null) {
            cur.next = pre;
            pre = cur;
            cur = next;
            next = next.next;
        }
        cur.next = pre;
        return cur;
    }
}
